ANOVA Pizza Case: 1 factor 3 level In a good pizza restaurant, the three pizzaiolos argue about who bakes the best pizza. They bake 5 pizzas each, and invite 15 random gourmets to sample the pizza. The grade the taste numerically, such that higher numbers mean better taste.

First, lets input the data. We will use a dataframe.

In [2]:
mydataframe <- data.frame("Taste" = c(51,45,33,45,67,23,43,23,43,45,56,76,74,87,56), "Names" = c(rep("Alberto",5),rep("Francesco",5),rep("Paolo",5)))
str(mydataframe)
'data.frame':	15 obs. of  2 variables:
 $ Taste: num  51 45 33 45 67 23 43 23 43 45 ...
 $ Names: Factor w/ 3 levels "Alberto","Francesco",..: 1 1 1 1 1 2 2 2 2 2 ...
In [3]:
plot(mydataframe$Taste)
No description has been provided for this image

We have 3 groups with n_i=5 points each, so the degrees of freedom for SST:3-1=2 and for SSE:15-3=12. Indeed, we find 12+2=14=n-1. Now we need to compute the statistical parameters of the groups.

In [4]:
# Compute all variances = standard deviation ^2
s1sq=sd(mydataframe$Taste[1:5])^2
s2sq=sd(mydataframe$Taste[6:10])^2
s3sq=sd(mydataframe$Taste[11:15])^2

# Compute all group averages
a1=mean(mydataframe$Taste[1:5])
a2=mean(mydataframe$Taste[6:10])
a3=mean(mydataframe$Taste[11:15])

# Compute global average
a=mean(mydataframe$Taste)

Next we can compute SS, SST, SSE:

In [7]:
SS=sum((mydataframe$Taste-a)^2)
SST=  5*(a1-a)^2 + 5*(a2-a)^2 + 5*(a3-a)^2
SSE= (5-1)*s1sq + (5-1)*s2sq + (5-1)*s3sq
SS
SST
SSE
4883.73333333333
3022.93333333333
1860.8

Always test that SST+SSE=SS!!

In [8]:
SST+SSE
4883.73333333333

Now we compute the mean squares by normalizing the sum of squares by their respective degrees of freedom

In [9]:
MST=SST/2
MSE=SSE/12
MST
MSE
1511.46666666667
155.066666666667

Now we compute the F-statistic:

In [10]:
F=MST/MSE
F
9.74720550300946

This is a large F, but to make a statistical statement we need to compare it to the quantile of the F-distribution. Large values of F disprove H0, so we find the maximal F at which we still accept H0 at a level of significance 0.05 as:

In [11]:
F_crit=qf(0.95,2,12)  #(q)uantile of the (f)-distribution at alpha, with df1 and df2 degrees of freedom.
F_crit
3.88529383465239

Indeed, our F is significantly above the critical value, so we can reject the null hypothesis that all pizza are equivalent. Clearly there are better and worse bakers in the restaurant.

Let us redo all with internal R commands:

In [12]:
aov.out=aov(Taste~Names, data=mydataframe)
In [13]:
summary(aov.out)
            Df Sum Sq Mean Sq F value  Pr(>F)   
Names        2   3023  1511.5   9.747 0.00306 **
Residuals   12   1861   155.1                   
---
Signif. codes:  0 ‘***’ 0.001 ‘**’ 0.01 ‘*’ 0.05 ‘.’ 0.1 ‘ ’ 1
In [ ]: